package online.hashmall.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import online.hashmall.api.ApiController;
import online.hashmall.api.R;
import online.hashmall.dto.LoginDTO;
import online.hashmall.service.LoginService;
import online.hashmall.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 登录
 *
 * @author jpq
 * @email jinpqa@163.com
 * @since 2024/5/18 上午10:06
 */
@RestController
@RequestMapping("/auth")
public class LoginController extends ApiController {

    @Autowired
    private LoginService loginService;

    /**
     * 用户登录
     * @param loginDTO 用户登录信息
     * @return LoginVO
     */
    @SaIgnore
    @PostMapping("/oauth2/token")
    public LoginVO login(@Validated @RequestBody LoginDTO loginDTO) {
        return loginService.login(loginDTO);
    }

    /**
     * 退出登录
     * @return JsonResult<String>
     */
    @SaIgnore
    @DeleteMapping("/token/logout")
    public R<String> logout() {
        loginService.logout();
        return success();
    }
}
